//
//  MineViewController.swift
//  Box
//
//  Created by mn on 2025/3/30.
//
import UIKit
import SnapKit

enum MineMenu: String,CaseIterable {
    case address = "地址信息"
//    case cashRedEnvelope = "现金红包"
}


class MineViewController: UIViewController, UITableViewDataSource,UITableViewDelegate {
    private let tableView = UITableView()
    let titles = MineMenu.allCases
    lazy var tableHeaderView = MineHeaderView(frame: CGRect(x: 0, y: 0, width: Int(UIScreen.main.bounds.width), height: 325+98-20))
    override func viewDidLoad() {
        super.viewDidLoad()
        tableView.backgroundColor = .black

        view.addSubview(tableView)
        tableView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        tableView.bounces = false
        tableView.dataSource = self
        tableView.delegate = self
        tableView.tableHeaderView = tableHeaderView
        tableView.contentInsetAdjustmentBehavior = .never
    }
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        getUserInfo()
    }
    func getUserInfo() {
        UserManager.shared.update {
            [weak self]  in
            self?.tableHeaderView.reload()
        }
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        titles.count
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell") ?? UITableViewCell(style: .default, reuseIdentifier: "cell")
        cell.textLabel?.text = titles[indexPath.row].rawValue
        cell.textLabel?.textColor = .init(hex: "#E1E1E1")
        cell.textLabel?.font = UIFont.systemFont(ofSize: 15,weight: .bold)
        cell.imageView?.image = UIImage.mineAddress
        cell.backgroundColor = .clear
        let arrowImageView = UIImageView(image: UIImage.arrowRight)
        arrowImageView.contentMode = .scaleAspectFit
        cell.selectionStyle = .none
        cell.accessoryView = arrowImageView
        return cell
    }
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let titleLabel = UILabel()
        titleLabel.text = "  其他功能"
        titleLabel.textColor = .white
        titleLabel.font = UIFont.boldSystemFont(ofSize: 16)
        return titleLabel
    }
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        40
    }
    func viewForZooming(in scrollView: UIScrollView) -> UIView? {
        UIView()
    }
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        0
    }
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        if titles[indexPath.row] == .address{
            let vc = AddressViewController()
            navigationController?.push(vc)
        }
    }

}
